// SPDX-License-Identifier: GPL-2.0
/*
 *  linux/fs/read_write.c
 *
 *  Copyright (C) 1991, 1992  Linus Torvalds
 *  Copyright (c) Huawei Technologies Co., Ltd. 2024-2024. All rights reserved.
 *  Author: Huawei OS Kernel Lab
 *  Create: Mar 15 16:14:23 2024
 */
#include <linux/fcntl.h>
#include <linux/export.h>
#include <asm/override.h>

long __override do_sys_open(int dfd, const char *filename, int flags, unsigned short mode)
{
	return liblinux_pal_ksys_openat(dfd, filename, flags, mode);
}

long ksys_open(const char __user *filename, int flags,
			     umode_t mode)
{
	if (force_o_largefile())
		flags |= O_LARGEFILE;
	return do_sys_open(AT_FDCWD, filename, flags, mode);
}
EXPORT_SYMBOL(ksys_open);

int __close_fd(struct files_struct *files, unsigned int fd)
{
	liblinux_pal_ksys_close(fd);
	return 0;
}
EXPORT_SYMBOL(__close_fd);

long ksys_access(const char *filename, int mode)
{
	return (long)liblinux_pal_ksys_access(filename, mode);
}
EXPORT_SYMBOL(ksys_access);

long ksys_rename(const char *oldname, const char *newname)
{
	return (long)liblinux_pal_ksys_rename(oldname, newname);
}
EXPORT_SYMBOL(ksys_rename);

long ksys_mkdir(const char *pathname, unsigned short mode)
{
	return (long)liblinux_pal_ksys_mkdir(pathname, mode);
}
EXPORT_SYMBOL(ksys_mkdir);

long ksys_rmdir(const char *pathname)
{
	return liblinux_pal_ksys_rmdir(pathname);
}
EXPORT_SYMBOL(ksys_rmdir);

ssize_t __override ksys_write(unsigned int fd, const char *buf, size_t count)
{
	return liblinux_pal_ksys_write(fd, buf, count);
}
EXPORT_SYMBOL(ksys_write);

ssize_t __override ksys_read(unsigned int fd, char *buf, size_t count)
{
	return liblinux_pal_ksys_read(fd, buf, count);
}
EXPORT_SYMBOL(ksys_read);

off_t __override ksys_lseek(unsigned int fd, off_t offset, unsigned int whence)
{
	int64_t tmp = 0;
	int ret = 0;
	
	ret = liblinux_pal_ksys_lseek(fd, offset, whence, &tmp);
	return ret >= 0 ? tmp : ret;
}
EXPORT_SYMBOL(ksys_lseek);

int ksys_fsync(unsigned int fd)
{
	return liblinux_pal_ksys_fsync(fd);
}
EXPORT_SYMBOL(ksys_fsync);
